package com.java.test.timer;

import com.java.test.user.dto.PlayAccountInfo;
import com.java.test.user.service.MemberService;
import com.java.test.util.MemberUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * UserTimer
 *
 * @author lijie1
 * @version 1.0
 * @date 2020/7/21 0021 16:16
 */
@Slf4j
@Component
@EnableScheduling
public class UserTimer {

    @Autowired
    private MemberService memberservice;


    @Scheduled(cron = "*/1 * * * * ?")
    public void run() {
        int i = memberservice.getMemberListSize();
        if(i>MemberUtil.size){
            MemberUtil.size = i;
            List<PlayAccountInfo> userEntityListNow = memberservice.getMemberListNow();
            for (PlayAccountInfo obj:userEntityListNow) {
                MemberUtil.memberInfoMap.put(obj.getAccountName(),obj);
            }
            List<PlayAccountInfo> userEntityListOld= memberservice.getMemberListOld();
            for (PlayAccountInfo obj:userEntityListOld) {
                MemberUtil.memberInfoMap.put(obj.getAccountName(),obj);
            }
        }

    }

}
